// pages/healthcoinDetail/index.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataArr:[],
    isFromHome:false,
    allCoin:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    var that = this
    this.setData({
      isFromHome:options.id=='true'
    })
    console.log(this.data.isFromHome)
    if(options.id=='false'){
      wx.setNavigationBarTitle({
        title: '健康币明细',
      })
      app.post(app.Apis.GET_COIN_DETAIL, {
        userId: app.userId,
        storeId: app.mainStoreId,
      }, result => {
        console.log(result)
        if (result.success && result.dataList.length > 0){
          that.setData({
            dataArr: result.dataList
          })
        }
      })
    }else{
      wx.setNavigationBarTitle({
        title: '药品评价',
      })
      let date = new Date()
      var year = date.getFullYear()
      var month = date.getMonth() + 1
      var day = date.getDate()
      if (month > 0 && month < 10) {
        month = '0' + month
      }
      if (day >= 0 && day <= 9) {
        day = "0" + day
      }
      let nowDate = String(year) + month + day + '235959'
      console.log(nowDate)
      app.post(app.Apis.GET_DRUG_ALLANSWERDETAIL,{
        mainStoreId:app.mainStoreId,
        consultDrugId:app.consultDrugId,
        bDateT:'20180608000000',
        eDateT: nowDate
      },reslut=>{
        console.log(reslut)
        if (reslut.success && reslut.dataList.length > 0){
          that.setData({
            dataArr: reslut.dataList
          })
        }
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    that.getMyUserInfo(result=>{
      that.setData({
        allCoin: result.data.totalCoin
      })
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  clickTXAction(){
    wx.navigateTo({
      url: '/pages/myCoin/index',
    })
  },
  clickListAction(e){
    console.log(e)
    app.drugList = this.data.dataArr[Number(e.currentTarget.id)]
    console.log(app.drugList)
    // return
    wx.navigateTo({
      url: '/pages/evaluateDetail/index?id='+true,
    })
  },
  getMyUserInfo(callBack) {
    app.post(app.Apis.GET_USER_INFO, {
      userId: app.userId,
      storeId: app.mainStoreId
    }, result => {
      console.log(result)
      callBack(result)
    })
  },

})